/*
 * Copyright (C) Francisco Morero Peyrona. All rights reserved.
 *
 * This software is published under the terms of Open Source
 * License version 1.1, a copy of which has been included with this
 * distribution in the License.txt file.
 */
 
package jdbcmanager.dbtools.datatypes;

/**
 * Each one of the columns that can compose an index.
 * <p>
 * IndexDefinition contains (among other things) a set of instances of this class. 
 * 
 * @author Francisco Morero Peyrona
 */
public final class IndexColumnDefinition implements Cloneable
{
   private String  sColName;
   private boolean bUnique;
   private boolean bAscending;
   private String  sFilter;

   //-------------------------------------------------------------------------//
   
   public IndexColumnDefinition()
   {
      this( "", false, true, "" );   
   }
   
   public IndexColumnDefinition( String sColName, boolean bUnique, boolean bAscending, String sFilter )
   {
      setName( sColName );
      setUnique( bUnique );
      setAscending( bAscending );
      setFilter( sFilter );
   }

   public String   getName()     { return this.sColName;   }
   public boolean  isAscending() { return this.bAscending; }
   public boolean  isUnique()    { return this.bUnique;    }
   public String   getFilter()   { return this.sFilter;    }

   public void setName( String sName )       { this.sColName   = sName.trim();                     }
   public void setAscending( boolean bAsc )  { this.bAscending = bAsc;                             }
   public void setUnique( boolean bUnique )  { this.bUnique    = bUnique;                          }
   public void setFilter( String sFilter )   { this.sFilter    = (sFilter == null) ? "" : sFilter; }


   public boolean equals( Object obj )
   {
      boolean bRet = false;

      if( obj != null && obj instanceof IndexColumnDefinition )
      {
         IndexColumnDefinition col = (IndexColumnDefinition) obj;

         bRet = col.sColName.equals( this.sColName ) &&
                col.bUnique    == this.bUnique       &&
                col.bAscending == this.bAscending    &&
                col.sFilter.equals( this.sFilter );
      }

      return bRet;
   }
}